package com.example.designpattern;

/**
 * Author 方隽琦
 * Date 2020/12/30
 * Description
 */
public class ImageLoderConfig {

    private ImageCache imageCache = new MemoryCache();
    //加载图片是的loading 和加载失败的图片配置对象
    private DisplayConfig displayConfig = new DisplayConfig();

    private LoaderPolicy loaderPolicy = new LoaderPolicy();

    private int threadCount = Runtime.getRuntime().availableProcessors() + 1;


    private ImageLoderConfig(){}


    public static class Builder{

        //以下是默认设置
        ImageCache imageCache = new MemoryCache();

        DisplayConfig displayConfig = new DisplayConfig();

        LoaderPolicy loaderPolicy = new LoaderPolicy();

        int threadCount = Runtime.getRuntime().availableProcessors() + 1;

        public Builder setThreadCount(int count){
            threadCount = Math.max(1,count);
            return this;
        }

        public Builder setLoadingPlaceHolder(int ResId){
            displayConfig.loadingResId = ResId;
            return this;
        }

        public Builder setNotFoundPlaceHolder(int ResId){
            displayConfig.failedResId = ResId;
            return this;
        }

        public Builder setLoadPolicy(LoaderPolicy policy){
            loaderPolicy = policy;
            return  this;
        }
        public Builder setCache(ImageCache cache){
            imageCache = cache;
            return this;
        }

        void applyConfig(ImageLoderConfig config){
            config.imageCache = this.imageCache;
            config.displayConfig = this.displayConfig;
            config.loaderPolicy = this.loaderPolicy;
            config.threadCount = this.threadCount;
        }

        public ImageLoderConfig create(){
            ImageLoderConfig config = new ImageLoderConfig();
            applyConfig(config);
            return config;
        }






    }


}
